﻿/*
* Autor Zero
* version 1.1
* arreglé un temita que había con el texto animado, ahora no se cuelga más porque le borro el onEnterFrame cuando hago un setTextPelado
*/

class com.dinmax.flash.central.bridge.MARQUEEBridge extends MovieClip {
	
	private var LIMIT:Number=80;
	private var msg:String;
	private var txt_marquee:TextField;
	private var parent:MovieClip;
	
	private var _toolTipCont:MovieClip;
	private var mcToolTip:MovieClip;
	public static var nTIP_TIME:Number=600; // tiempo necesario para el tooltip;
	public static var nTOOLTIP_Y:Number=30; // offset en Y del tooltip;

	function MARQUEEBridge(){
		if(_toolTipCont == undefined){
			_toolTipCont = this.createEmptyMovieClip("container", this.getNextHighestDepth());
		};
	};

	function onLoad():Void {
		
	};
	
	function onPress():Void {
		this._parent.mcFondo.onPress();
	};
	
	function onRelease():Void {
		this._parent.mcFondo.onRelease();
	};
	
	function onReleaseOutside():Void {
		this.onRelease();
	};
	
	function onRollOver():Void {
		//parent.pressMarquee();
		if(this.msg.length > 13){
			var root:MARQUEEBridge = this;
			var nTimer:Number= getTimer();
	
			_toolTipCont.onEnterFrame=function(){
				var nDif:Number= getTimer() - nTimer;
					
				if(nDif > nTIP_TIME){
					trace("MARQUEEBridge.as | 34 | llegué hasta acá");
					delete this.onEnterFrame;
					root.mcToolTip=root.attachMovie("ToolTip", "mcToolTip", root.getNextHighestDepth(), { _x: root._x, _y: root._y- root.nTOOLTIP_Y});
					root.mcToolTip.tooltip = root.msg;
				};
			};
		};
	};
	
	function onRollOut():Void {
		delete _toolTipCont.onEnterFrame;
		this.mcToolTip.remove();
	};

	public function setText(msg:String):Void {
		//trace("\n---MarqueeBridge.as | setText() msg="+msg+" ---\n");
		delete this.onEnterFrame;
		if(this.msg != msg){
			this.msg = msg;
			txt_marquee.text=msg;
		}
	}; //fin funci
	public function setAnimateText(msg:String):Void {
		//trace("\n---MARQUEEBridge setAnimateText msg= "+msg+" ---\n");
		if(this.msg != msg){
			this.msg = msg;
			deleteText(msg);
		}
	}; //fin funci	
	
	private function deleteText(msg:String):Void {
		var nTimer:Number= getTimer();
		var nLimit:Number= LIMIT;
		var root:MovieClip= this;
		this.onEnterFrame=function(){
			var nDif:Number= getTimer() - nTimer;
			if(nDif > nLimit){
				if(txt_marquee.text.length==0){
					delete this.onEnterFrame;
					writeText(msg);
				} else {
					nTimer= getTimer();
					txt_marquee.text=txt_marquee.text.substr(1);
				}			
			};
		};
	};

	private function writeText(msg:String):Void {
		
		var nTimer:Number= getTimer();
		var nLimit:Number= LIMIT;
		
		this.onEnterFrame=function(){
			var nDif:Number= getTimer() - nTimer;
			if(nDif > nLimit){
				if(txt_marquee.text==msg){
					delete this.onEnterFrame;
				} else {
					nTimer= getTimer();
					txt_marquee.text=msg.substr(msg.length-txt_marquee.text.length-1);
				}			
			};
		};
	};

}; //fin de clase